#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int n;
struct p{
	string name;
	long long t;
};
bool cmp(p a, p b){
	return a.t < b.t;
}
int main(){
	p a[100005];
	cin >> n;
	int h, m, s;
	for (int i = 0; i < n; i++){
		cin >> a[i].name;
		scanf("%d:%d:%d", &h, &m, &s);
		a[i].t = ((h * 60) + m) * 60 + s;
	}
	sort(a, a + n, cmp);
	for (int i = 0; i < n; i++){
		int begin = i, end = i, flag = 1;
		for (int j = 0; j < n; j++){
			if (abs(a[i].t - a[j].t) <= 3600 && flag){
				flag = 0;
				begin = j;
			}
			else if (abs(a[i].t - a[j].t) <= 3600){
				end = j;
			}
			if (!flag && abs(a[i].t - a[j].t) > 3600)break;
			
		}
		cout << a[i].name << " " << end - begin << endl;
		
	}

    return 0;
}


